<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          ref="input"
          placeholder="请输入商品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="userPhone">
        <el-input
          v-model="queryParams.userPhone"
          ref="input"
          placeholder="请输入商品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="walletList"
    >
      <el-table-column
        label="序号"
        type="index"
        align="center"
        :index="indexMethod"
        width="50px"
      />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="用户名称" align="center" prop="userName" />
      <el-table-column label="余额" align="center" prop="account" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="280"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleChangeState(scope.row)"
            v-if="scope.row.status == '20'"
            v-hasPermi="['system:goods:changeState']"
            >下架
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    
  </div>
</template>

<script>
import {
  balance
} from "@/api/system/wallet";
import { mapGetters } from "vuex";
import { getToken } from "@/utils/auth";
import store from "@/store";

export default {
  name: "Goods",
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,
        userPhone: undefined
      },

      walletList: [],
      total: 0,
      loading: false
    };
  },

  created() {
    const roles = store.getters && store.getters.roles;
    if (roles.indexOf("admin") > -1) {
      this.isExpand = true;
    }
    this.getList();
  },
  methods: {
    indexMethod(index) {
      return (
        index + 1 + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
      );
    },
    /** 查询商品信息列表 */
    getList() {
      this.loading = true;
      balance(this.queryParams).then((response) => {
        this.walletList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        goodsVideo: undefined,
        goodsId: undefined,
      };
      console.log(this.form);
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    arrToStr(arr) {
      if (arr.length <= 0) return "";
      return arr
        .map((item) => {
          return item.response.url;
        })
        .join(",");
    },
    strToArr(str) {
      if (str == "") return [];
      return str.split(",").map((item) => {
        return {
          url: item,
          response: {
            url: item,
          },
        };
      });
    }
  }
};
</script>
<style scoped>
</style>
